from typing import List


class Solution:
    def maxSubArray(self, nums: List[int]) -> int:
        ans = nums[0]
        tempSum = 0
        for i in range(0, len(nums)):
            tempSum += nums[i]
            ans = max(ans, tempSum)
            if tempSum < 0:
                tempSum = 0
        return ans